package com.qzc;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.Resource;
import javax.sql.DataSource;

@SpringBootApplication
@EnableTransactionManagement
public class MovedataApplication {
    @Resource(name = "dataSourceOrigin")
    private DataSource dataSourceOrigin;
    @Resource(name = "dataSourceTarget")
    private DataSource dataSourceTarget;


    public static void main(String[] args) {
        SpringApplication.run(MovedataApplication.class, args);
    }
    @Bean(name = "jdbcTemplateOrigin")
    public JdbcTemplate jdbcTemplateOrigin(){
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(dataSourceOrigin);
        return jdbcTemplate;
    }
    @Bean(name = "jdbcTemplateTarget")
    public JdbcTemplate jdbcTemplateTarget(){
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(dataSourceTarget);
        return jdbcTemplate;
    }


    @Bean(name = "jdbcTemplate")
    public JdbcTemplate jdbcTemplate(){
        DruidDataSource druidDataSource=new DruidDataSource();
        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        druidDataSource.setPassword("kmeboa");
        druidDataSource.setUsername("kmeboa");
        druidDataSource.setUrl("jdbc:mysql://192.168.100.99:3306/ynswtoadb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC");
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(druidDataSource);

        return jdbcTemplate;
    }
}
